package servlet;

import Dao.StudentDao;
import Impl.StudentDaoImpl;
import com.google.gson.Gson;
import model.Student;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet("/StudentMsgByStuNoServlet")
public class StudentMsgByStuNoServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=utf-8");

        //1.获取信息
        String stuNo=request.getParameter("No");
        StudentDaoImpl studentDao = new StudentDao();
        List<Student> student=studentDao.getStudentByStuNo(stuNo);

        //传回数据
        PrintWriter writer=response.getWriter();
        Gson gson=new Gson();
        writer.write(gson.toJson(student));
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
